package homework.test2;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class ServiceDemo2 {
    public static void main(String[] args) throws IOException {
        //3.服务器确定地址
        ServerSocket ss = new ServerSocket(10002);
        System.out.println("----服务器接收中----");
        Socket sk = ss.accept();
        System.out.println("----服务器已接收----");

        //4.服务器接收
        BufferedReader br = new BufferedReader(new InputStreamReader(sk.getInputStream()));
        String s;
        while ((s = br.readLine()) != null) {
            System.out.println("客户端:"+s);
        }

        //5.服务器回复
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(sk.getOutputStream()));
        bw.write("怕了怕了");
        bw.newLine();
        bw.write("小黑子不得好屎");
        bw.flush();

        //6.释放
        bw.close();
        br.close();
        sk.close();
        ss.close();
    }
}
